//
//  TimeUitl.swift
//  SwiftStudyDemoAll
//
//  Created by BINGO on 2019/5/12.
//  Copyright © 2019 mrlong. All rights reserved.
//

import Foundation
class TimeUtil  {
    func getCurrTimeStamp() -> Int {
        //获取当前时间
        let now = NSDate()
        
        // 创建一个日期格式器
        let dformatter = DateFormatter()
        dformatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
        
        //当前时间的时间戳
        let timeInterval:TimeInterval = now.timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        
        return timeStamp;
    }
    let yyyy_MM_dd_HH_mm_ss:String = "yyyy年MM月dd日 HH:mm:ss"
    let yyyy_MM_dd_HH_mm_ss2:String = "yyyy/MM/dd HH:mm:ss"
    let yyyy_MM_dd_HH_mm_ss3:String = "yyyy-MM-dd HH:mm:ss"
    let yyyy_MM_dd_HH_mm:String = "yyyy年MM月dd日 HH:mm"
    let HH_mm_ss:String = "HH:mm:ss"
    let yyyy_MM_dd:String = "yyyy年MM月dd日"
    let MM_dd_HH_mm_ss:String = "MM月dd日 HH:mm:ss"
    
    func formatTimeStamp(timeStamp:Int,style:String) -> String {
        //转换为时间
        let timeInterval:TimeInterval = TimeInterval(timeStamp)
        let date = NSDate(timeIntervalSince1970: timeInterval)
        
        //格式话输出
        let dformatter = DateFormatter()
        dformatter.dateFormat = style
        
        return dformatter.string(from: date as Date)
    }
}
